﻿using System;
using System.Collections.ObjectModel;
using OperationPlugins.Reflections;
using OperationPlugins.Validators;

namespace OperationPlugins.Mvc.Filters
{
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
    public sealed class NotificationRouterAttribute : NotificationRouterForAllActionsAttribute
    {
        protected override void HandleNotifications(ReadOnlyCollection<Message> notifications)
        {
            // Prevent duplicate handling!
            if (ActionExecutingContext.ActionDescriptor.ControllerDescriptor.ControllerType.HasAttribute<NotificationRouterForAllActionsAttribute>())
            {
                return;
            }
            
            base.HandleNotifications(notifications);
        }
    }
}
